package com.sgb.knowledgeshare.viewmodel;

import android.util.Log;
import androidx.lifecycle.ViewModel;
import com.sgb.knowledgeshare.ShareConfig;
import com.sgb.knowledgeshare.view.fragment.ShareClassifyListFragment;
import com.swgk.core.base.api.ICallBack;
import com.swgk.core.base.model.entity.BaseEntity;
import com.swgk.core.dialog.DialogHelper;
import com.swgk.core.view.entity.VideoListEntity;
import java.util.HashMap;
import java.util.Map;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

/**
 * Created by fq
 * on 2020/9/9
 * 分类信息接口处理
 */
public class ShareClassifyListModel extends ViewModel {
    ShareClassifyListFragment fragment;

    public void setActivity(ShareClassifyListFragment shareClassifyListFragment) {
        fragment = shareClassifyListFragment;
    }
//    获取对应的类型列表数据
    public void getVideoTypeList(int page, String no) {
        Map map = new HashMap();
        map.put("pageNum",page);
        map.put("pageSize",10);
        map.put("type",no);//类型id
        Log.e("tag","pageNum:"+page+"  type:"+ no);
        DialogHelper.showProgressDialog(fragment.getContext(), null, "加载中...", 0, true, null).setCanceledOnTouchOutside(false);
        ShareConfig.getInstance().getApi().getVideoListByType(map).enqueue(new ICallBack<BaseEntity<VideoListEntity>>() {
            @Override
            public void onSuccess(BaseEntity<VideoListEntity> data) {
                DialogHelper.dismissProgressDialog();
                if (data.getData()==null)return;
                if (data.getState().equals("ok")){
                    fragment.setVideoTypeList(data.getData());
                }
            }
        });
    }

}
